package com.rabbiter.association.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class AlipayConfig {
    private final AlipayClientConfig alipayClientConfig;

    @Bean
    public AlipayClient alipayClient() {
        // 初始化AlipayClient
        return new DefaultAlipayClient(
                alipayClientConfig.getGatewayUrl(),
                alipayClientConfig.getAppId(), // 商户应用ID
                alipayClientConfig.getMerchantPrivateKey(), // 商户私钥
                "json", // 请求数据格式
                "utf-8", // 请求编码格式
                alipayClientConfig.getAlipayPublicKey(), // 支付宝公钥
                "RSA2" // 签名方式
        );
    }
}